﻿using BCCommon;
using BCData.OA.Notification.NotificationTransferRecord;
using BCDto.OA.Notification.NotificationTransferRecord;
using BCEntity.OA.Notification.NotificationTransferRecord;
using BCService.Utils;
using System;
using System.Collections.Generic;
using System.Text;

namespace BCService.OA.Notification.NotificationTransferRecord
{
    public class NotificationTransferRecordService : INotificationTransferRecordService
    {
        private readonly INotificationTransferRecordData notificationTransferRecordData;

        public NotificationTransferRecordService(INotificationTransferRecordData notificationTransferRecordData)
        {
            this.notificationTransferRecordData = notificationTransferRecordData;
        }

        public bool Exists(long notificationTransferRecordId)
        {
            return this.notificationTransferRecordData.Exists(notificationTransferRecordId).GetAwaiter().GetResult();
        }

        public NotificationTransferRecordDto Add(NotificationTransferRecordRequestDto requestDto)
        {

            var entity = requestDto.As<NotificationTransferRecordEntity>();

            return this.notificationTransferRecordData.Add(entity).GetAwaiter().GetResult().As<NotificationTransferRecordDto>();
        }
        public NotificationTransferRecordDto Update(NotificationTransferRecordPutDto putDto)
        {
            if (!this.Exists(putDto.NotificationTransferRecordId))
            {
                throw new ArgumentException("此记录不存在");
            }
            var entity = putDto.As<NotificationTransferRecordEntity>();

            return this.notificationTransferRecordData.Update(entity).GetAwaiter().GetResult().As<NotificationTransferRecordDto>();
        }

        public bool Delete(long notificationTransferRecordId)
        {
            if (!this.Exists(notificationTransferRecordId))
            {
                throw new ArgumentException("此记录不存在");
            }

            return this.notificationTransferRecordData.Delete(notificationTransferRecordId).GetAwaiter().GetResult();
        }

        public NotificationTransferRecordDto GetEntity(long notificationTransferRecordId)
        {
            return this.notificationTransferRecordData.GetEntity(notificationTransferRecordId).GetAwaiter().GetResult().As<NotificationTransferRecordDto>();
        }

        public IEnumerable<NotificationTransferRecordDto> GetList()
        {
            return this.notificationTransferRecordData.GetList().GetAwaiter().GetResult().As<IEnumerable<NotificationTransferRecordDto>>();
        }

        public PageableList<NotificationTransferRecordDto> Query(int pageIndex, int pageSize)
        {
            var (list, count) = this.notificationTransferRecordData.Query(pageIndex, pageSize).GetAwaiter().GetResult();

            return new PageableList<NotificationTransferRecordDto>
            {
                Items = list.As<IEnumerable<NotificationTransferRecordDto>>(),
                Count = count,
                PageIndex = pageIndex,
                PageSize = pageSize
            };
        }
    }
}
